package cn.liutao.bill.api;

import cn.hutool.core.util.StrUtil;
import cn.liutao.bill.service.BillService;
import cn.liutao.bill.vo.RankVO;
import cn.liutao.bill.vo.TasteRankVo;
import cn.liutao.common.utils.AuthUtils;
import cn.liutao.common.utils.ServletUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author liutao
 * @Description 菜品口味销量排行
 * @date 2023/11/5
 */
@WebServlet("/bill/tasteRank")
public class TasteRankServlet extends HttpServlet {

    private BillService billService;
    @Override
    public void init() throws ServletException {
        billService = BillService.getInstance();
    }

    /**
     * 菜系销售情况排行
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AuthUtils.isAdmin();
        String parameter = req.getParameter("orderBy");
        Integer orderBy = 0;
        if (StrUtil.isNotEmpty(parameter)) {
            orderBy = Integer.valueOf(parameter);
        }
        List<TasteRankVo> list = billService.getTasteRank(orderBy);
        ServletUtils.ok(resp,list);
    }
}
